﻿using System.Net;
using UnityEngine;

namespace BToolkit
{
    public class NetworkHelper
    {
        /// <summary>
        /// 获取内网IP
        /// </summary>
        public static string GetInternalIP()
        {
            IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily.ToString() == "InterNetwork")
                {
                    return ip.ToString();
                }
            }
            return null;
        }

        public static void LogBytes(byte[] bytes)
        {
            string str = "";
            for (int i = 0; i < bytes.Length; i++)
            {
                if (!string.IsNullOrEmpty(str)) str += ",";
                str += bytes[i];
            }
            Log(str);
        }

        public static void Log(object obj)
        {
            Debug.Log($"<color=#8DDED2>[Network] {obj}</color>");
        }

        public static void LogError(object obj)
        {
            Debug.LogError($"[Network] {obj}");
        }

    }
}
